//
//  ShoppingCartStoreTagView.m
//  Yanwei
//
//  Created by Believer Just on 2017/12/19.
//  Copyright © 2017年 DCloud. All rights reserved.
//

#import "ShoppingCartStoreTagView.h"
#import "UIView+Util.h"

@interface ShoppingCartStoreTagView ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *detailLabel;

@end

@implementation ShoppingCartStoreTagView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
        // 初始化视图
        [self initView];
    }
    return self;
}

/** 初始化视图 */
- (void)initView {
    self.titleLabel.text = @"折扣";
    CGSize size = TextSize_MutiLine(self.titleLabel.text, APPFONT(12), CGSizeMake(ScreenWidth /2, self.titleLabel.height));
    [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(size.width +14);
    }];
    
    self.detailLabel.text = @"已享“满100打8折”";
}

- (void)setModel:(PromoteSpuRspCouponsAndCampaignsModel *)model {
    _model = model;
    
    self.titleLabel.text = _model.promoteTypeName;
    CGSize size = TextSize_MutiLine(self.titleLabel.text, APPFONT(12), CGSizeMake(ScreenWidth /2, self.titleLabel.height));
    [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(size.width +14);
    }];
    self.detailLabel.text = _model.name;
}


#pragma mark - 懒加载
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.textColor = Color175030;
        _titleLabel.cornerRadius = 2;
        _titleLabel.layer.borderWidth = 0.5;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.layer.borderColor = Color175030.CGColor;
        _titleLabel.font = APPFONT(12);
        [self addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(15);
            make.centerY.equalTo(self);
        }];
        [_titleLabel layoutIfNeeded];
    }
    return _titleLabel;
}
- (UILabel *)detailLabel {
    if (!_detailLabel) {
        _detailLabel = [UILabel new];
        _detailLabel.textColor = Color175030;
        _detailLabel.font = APPFONT(12);
        _detailLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_detailLabel];
        [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLabel.mas_right).with.offset(10);
            make.centerY.equalTo(self.titleLabel);
            make.right.equalTo(self).with.offset(- 15);
        }];
    }
    return _detailLabel;
}

@end
